<?$this->load->view("/inc/header_inc")?>
   <?$this->load->view("/inc/nav_inc")?>
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><a href="/home">首页</a> </li>
                <li class="active">个人资料</li>
            </ul>
        </div>
        <div class="main-content">
            <div class="row">
                <div class="col-md-6">
                    <div id="myTabContent" class="tab-content">
                        <div class="tab-pane active in" id="home">
                            <p class="text-info">说明：帶*的为必填项。</p>
                            <form id="profileform" class="form-horizontal" name="profileform" method="post" action="/admin/user/updateProfile">
                                <input type="hidden" name="id" id="id" value="<?=$user['id']?>" >
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">姓名</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="name" name="name" value="<?=$user['username']?>" class="form-control" >
                                    </div>
                                    <div class="col-sm-2"><p class="text-warning">(*)</p></div>
                                </div>
                                <div class="form-group">
                                   <div class="btn-toolbar list-toolbar">
                                      <input type="submit" id="useraddbtn" name="useraddbtn" class="btn btn-success pull-right" value="保存"></input>
                                     </div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal small fade" id="successModal" tabindex="-1" role="dialog" aria-labelledby="successModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="myModalLabel">成功</h3>
                    </div>
                    <div class="modal-body">
                        <p class="error-text"><i class="fa fa-success modal-icon" ></i><span id="modal-success-content"></span></p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true" id="continue-btn">继续操作</button>
                        <button class="btn btn-danger" data-dismiss="modal" id="finish-btn">结束操作</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal small fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="errorModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="errorModalLabel">错误</h3>
                    </div>
                    <div class="modal-body">
                        <p class="error-text"><i class="fa fa-warning modal-icon" ></i><span id="modal-error-content"></span></p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">继续添加</button>
                        <button class="btn btn-danger" data-dismiss="modal">结束添加</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
     <script src="/static/javascripts/jquery-1.11.3.min.js" type="text/javascript"></script>
     <script src="/static/javascripts/bootstrap.min.js"></script>
     <script src="/static/javascripts/jquery.validate.min.js"></script>
     <script type="text/javascript">
    $(function(){
        var form = $( "#profileform" );
        form.removeAttr("novalidate");
        form.validate({
            rules: {
                name: {
                    required:true,
                    minlength:2,
                    maxlength:30
                }
            },
            messages: {
                name:{
                    required:"请输入用户名",
                    minlength:"不能少于{0}位",
                    maxlength:"不能多于{0}位"
                }
            },
            submitHandler:function (form) {
                $.ajax({
                    type: $(form).attr('method'),
                    url: $(form).attr('action'),
                    data: $(form).serialize(),
                    dataType : 'json'
                }).done(function (data) {
                    if (data.code == 1) {
                            showSuccess(data.msg);                           
                        } else {
                            showError(data.msg);
                        }
                    });
                  return false; // required to block normal submit since you used ajax
             }
        });
        $("#continue-btn").click(function(){
            window.location.reload();
        });
        $("#finish-btn").click(function(){
            window.location.href="/admin/user/profile";
        });

    });

    function showSuccess(content)
    {
        $('#successModal').modal('toggle');
        $('#successModal').modal('show');
        $("#modal-success-content").text(content);
    }

    function showError(content){
        $('#errorModal').modal('toggle');
        $('#errorModal').modal('show');
        $("#modal-error-content").text(content);
    }
</script>
</body>
</html>
